﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace Tecnorama.MobilSatis
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        LinqDataContext db = new LinqDataContext();

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.OpenForms["Form1"].Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            klavye1.Tipi = SanalKlavye.KlavyeTipi.Numerik;
            klavye1.Enabled = false;
                        comboBox1.Text = "Kullanıcı Adı Seçiniz";
            //var sorgu = from c in db.Personels select c;
            //db.SubmitChanges();
            //comboBox1.DataSource = sorgu;
            var sorgu = from x in db.Personels where x.YetkiID==4 where x.aktif==true select new { x.PersonelAdi, x.PersonelSoyadi };
            foreach (var item in sorgu)
            {
                comboBox1.Items.Add(item.PersonelAdi + " " + item.PersonelSoyadi);

            }

        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            klavye1.Enabled = true;
            ctr = textBox1;
            //System.Diagnotics.Process.Start("VirtualKeyboard3.exe");
            //Process.Start ("osk.exe");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var sorgu = (from x in db.Personels where x.PersonelAdi == comboBox1.Text.Split(' ')[0] where x.PersonelSoyadi == comboBox1.Text.Split(' ')[1] select x).FirstOrDefault();

            if (sorgu.Sifre == textBox1.Text)
            {

                Form2 frm2 = new Form2();
                frm2.Show();
                frm2.Text = comboBox1.Text;
                frm2.Tag = sorgu.PersonelID;
                this.Close();
                return;
            }
            MessageBox.Show("Hatalı Şifre");
            textBox1.Clear();
            textBox1.Select();
        }
        Control ctr;
        private void klavye1_Tuslandi(object sender, SanalKlavye.ButonaBasildi e)
        {
            if (klavye1.harf=="@")
            {
                ctr.Text = ctr.Text.Substring(0, ctr.Text.Length - 1);
                return;
            }
            ctr.Text += klavye1.harf;
        }

     
    }
}